var gulp = require('gulp');
var transport = require("gulp-seajs-transport"); //对seajs的模块进行预处理：添加模块标识
var concat = require("gulp-seajs-concat"); //seajs模块合并
var clean = require('gulp-clean');
var merge = require('merge-stream');
var uglify=require('gulp-uglify');

var config = {
    src: 'src',
    dest: 'dist'
}

//清除打包目录
gulp.task('clean', function () {
    return gulp.src(config.dest, {
        read: false
    }).pipe(clean());
});

//seajs transport
gulp.task('seajs', function () {
    return merge(
        gulp.src(config.src + '/js/!(plugins)/**/*.js')
        .pipe(transport())
        .pipe(concat( {
            base: config.src + '/js'
        }))
        // .pipe(uglify())
        .pipe(gulp.dest(config.dest + '/js')),

        gulp.src([config.src + '/js/sea.js', config.src + '/js/plugins/**/*.js'])
        .pipe(
            gulp.dest(config.dest + '/js')
        )
    );
});



gulp.task('default', ['clean'], function () {
    return gulp.start('seajs');
});